package com.powergisol.gis.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powergisol.gis.entity.TabMarkerColor;
import com.powergisol.gis.entity.TabMarkerStaticColor;
import com.powergisol.gis.service.TabDataSettingService;
import com.powergisol.gis.util.Result;
import com.powergisol.gis.vo.MarkerColorVo;
import com.powergisol.gis.vo.SearchConditionVo;
import com.powergisol.gis.vo.TabUserVo;
import com.powergisol.gis.vo.TcmcDetailVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * Description:数据查询相关
 */
@RestController
@RequestMapping(value = "data")
@Api(description = "数据预览" ,value = "数据预览")
public class TabDataController extends BaseController{
    @Autowired
    private TabDataSettingService tabDataSettingService;

    @RequestMapping(value = "3DModel/**", method = RequestMethod.GET)
    public Result modelBase(String serviceName,String pipeLx, Principal p){
        TabUserVo tabUserVo = getUser(p);
        Result result = new Result();
        List<Object> list = tabDataSettingService.listByServiceName(serviceName,pipeLx,tabUserVo.getId());
        result.setData(list);
        return result;
    }


    @RequestMapping(value = "listService", method = RequestMethod.POST)
    public Result listService(Principal p, SearchConditionVo vo){
        Result result = new Result();
        TabUserVo tabUserVo = getUser(p);
        vo.setUserId(tabUserVo.getId());
        PageHelper.startPage(vo.getPage(), vo.getLimit());
        PageInfo<Object> pageInfo = new PageInfo<>(tabDataSettingService.listByService(vo));
        result.setCount((int) pageInfo.getTotal());
        result.setData(pageInfo.getList());
        return result;
    }

    /**
     * 岩层生成时所包含的土层信息
     * @param settingId
     * @return
     */
    @RequestMapping(value = "listTcmc", method = RequestMethod.POST)
    public Result listTcmc(String settingId){
        Result result = new Result();
        List<TcmcDetailVo> list = tabDataSettingService.listTcmc(settingId);
        result.setData(list);
        return result;
    }


    @RequestMapping(value = "getMarkers", method = RequestMethod.POST)
    public Result getMarkers(String uuid){
        Result result = new Result();
        List<TabMarkerColor> list = tabDataSettingService.listByMarkers(uuid);
        result.setData(list);
        return result;
    }

    @RequestMapping(value = "getMarkersByCondition", method = RequestMethod.POST)
    public Result getMarkersByCondition(String uuid,String tcmc){
        Result result = new Result();
        TabMarkerColor tabMarkerColor = tabDataSettingService.getMarkersByCondition(uuid,tcmc);
        result.setData(tabMarkerColor);
        return result;
    }



    @RequestMapping(value = "setMarkerColor", method = RequestMethod.POST)
    public Result setMarkerColor(@RequestBody MarkerColorVo vo){
        return tabDataSettingService.setMarkerColor(vo.getColors());
    }


    @RequestMapping(value = "detail", method = RequestMethod.POST)
    public Result modelDetail(Integer settingId,Integer dataIndex,String ZKBH,String ZKX,String ZKY){
        Result result = new Result();
       // List<TabDataDetail> list = tabDataSettingService.listBySettingId(settingId, dataIndex);
        result.setData(tabDataSettingService.getDetailForZk(settingId,dataIndex,ZKBH,ZKX,ZKY));


        return result;
    }

    @RequestMapping(value = "listStaticMarker", method = RequestMethod.GET)
    public Result listStaticMarker(){
        Result result = new Result();
        List<TabMarkerStaticColor> staticColorList = tabDataSettingService.listStaticMarker();
        result.setData(staticColorList);
        return result;
    }


    @RequestMapping(value = "setMarker", method = RequestMethod.POST)
    public Result setMarker(@RequestBody TabMarkerStaticColor color){
        return tabDataSettingService.setStaticMarkers(color);
    }

    @RequestMapping(value = "delZkByServiceName", method = RequestMethod.POST)
    public Result delZkByServiceName(String serviceName){
        return tabDataSettingService.delZkByServiceName(serviceName);
    }

    /**
     * 根据服务名称删除相应的数据
     * @param serviceName
     * @return
     */
    @RequestMapping(value = "delDataByServiceName", method = RequestMethod.POST)
    public Result delDataByServiceName(String serviceName){
        return tabDataSettingService.delDataByServiceName(serviceName);
    }


}
